﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Medianamik.Core.Security;
using Medianamik.Core.Interfaces;
using System.Web.Security;

namespace Medianamik.Core.DAL
{
    public interface ISecurityDALProvider
    {
        IEnumerable<Permission> GetAllNodeTypePermissions();
        IEnumerable<InheritedPermission> GetAllNodeTypeInheritedPermissions();

        IEnumerable<Permission> GetAllNodePermissions();
        IEnumerable<InheritedPermission> GetAllNodeInheritedPermissions();

        void TransacApplyPermissionsToType(Guid typeId, IEnumerable<Guid> overriddenGroups,
                                           IEnumerable<Permission> deletedPermissions,
                                           IEnumerable<Permission> updatedPermission,
                                           IEnumerable<Permission> newPermissions);

        void TransacApplyPermissionsToNode(Guid nodeId, IEnumerable<Guid> overriddenGroups,
                                           IEnumerable<Permission> deletedPermissions,
                                           IEnumerable<Permission> updatedPermission,
                                           IEnumerable<Permission> newPermissions);
        //
        // Approbations
        //
        IEnumerable<Approbation> GetAllNodeApprobations();

        void AddNodeApprobation(Approbation approbation);
        void UpdateNodeApprobation(Approbation approbation);
        void DeleteNodeApprobation(Guid nodeId);

        #region Roles, Groups

        IEnumerable<IRole> GetRoles();
        IEnumerable<Group> GetGroups();
        IEnumerable<IUserInGroup> GetUsersInGroups();
        IEnumerable<Guid> GetUsersInGroups(IEnumerable<string> groups);
        IEnumerable<IRoleInGroup> GetRolesInGroups();
        void AddUsersToGroups(string[] pUsers, string[] pGroups);
        void AddRolesToGroups(string[] pRoles, string[] pGroups);
        void RemoveUsersFromGroups(string[] pUsers, string[] pGroups);
        void RemoveRolesFromGroups(string[] pRoles, string[] pGroups);
        void CreateRole(string pRoleName);
        void CreateGroup(string pGroupName, Guid parentGroupId);
        void DeleteRole(string pRoleName);
        void DeleteGroup(string pGroupName);

        #endregion

        #region Users

        IUser[] GetUsers(int pageIndex, int pageSize, out int recordCount);
        IUser[] GetUsersByName(string pUsernameToMatch, int pageIndex, int pageSize, out int recordCount);
        IUser CreateUser(string username, string password, MembershipPasswordFormat pPasswordFormat, string salt, string email, string passwordQuestion, string passwordAnswer, bool isApproved, Guid providerUserKey);
        void UpdateUser(string email, string comment, bool isApproved, bool isLockedOut, Guid providerUserKey);
        void DeleteUser(string username);
        void DeleteUser(Guid userId);
        IUser GetUser(string username);
        void LockUser(string username);
        void UnlockUser(string username);
        void SetLockUser(Guid userId, bool locked);
        IUser GetUser(Guid providerUserKey);
        void SetUserLastActivityDate(Guid providerUserKey, DateTime lastActivityDate);
        void SetUserPassword(Guid providerUserKey, string password, MembershipPasswordFormat pPasswordFormat, string salt);
        void SetUserPasswordQuestionAndAnswer(Guid providerUserKey, string passwordQuestion, string passwordAnswer);




        #endregion

        #region Pages

        IRole[] GetRolesForPage(Guid pPageId);
        void AddRolesToPage(Guid pPageId, string[] pRoles);
        void RemoveRolesFromPage(Guid pPageId, string[] pRoles);

        #endregion

        Guid[] GetVisiblePropertiesForGroups(string[] groupNames);
        void AddPropertiesForGroup(Guid[] properties, string group);
    }
}
